package com.controller.activiti;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.common.ActivitiUtils;

@Controller
@RequestMapping("/ActivitiMain")
public class ActivitiMainController {
	static final Logger logger = LoggerFactory.getLogger(ActivitiMainController.class);

	@Autowired
	ProcessEngine processEngine;

	@Autowired
	TaskService taskService;

	@Autowired
	HistoryService historyService;

	@Autowired
	RepositoryService repositoryService;

	@Autowired
	IdentityService identityService;

	@Autowired
	RuntimeService runtimeService;

	@Autowired
	FormService formService;

	@RequestMapping("/PendingTask")
	public String PendingTask(HttpServletRequest request) {
		return "activiti/PendingTask";
	}

	@RequestMapping("/HistoryTask")
	public String HistoryTask(HttpServletRequest request) {
		return "activiti/HistoryTask";
	}

	@RequestMapping("/WFImg")
	public String WFImg(HttpServletRequest request) {
		String taskId = request.getParameter("taskid");
		String devid = request.getParameter("devid");
		Map<String, Object> currentActivityCoordinates = ActivitiUtils.getCurrentActivityCoordinates(taskId,
				taskService, runtimeService, repositoryService);
		request.setAttribute("taskid", taskId);
		request.setAttribute("devid", devid);
		request.setAttribute("acs", currentActivityCoordinates);
		return "activiti/WFImg";
	}
}
